//package com.rt.mes.processmanagement.config;
//
//
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.annotation.MapperScan;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.io.Resource;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.core.io.support.ResourcePatternResolver;
//
//import javax.sql.DataSource;
//
///**
// * Created by herb on 2016/9/18.
// */
//
//@Configuration
//@MapperScan(basePackages = {MyBatisConfig.PACKAGE}, sqlSessionFactoryRef = "sqlSessionFactory")
//public class MyBatisConfig {
//
////    protected final Logger log = LoggerFactory.getLogger(this.getClass());
//
//    @Autowired
//    DataSource dataSource;
//
//    static final String PACKAGE = "com.zgys.mes.dao.mapper";
////    static final String ScanPackage = "com.rt.mes.processmanagement.scan.dao";
//    static final String CONFIG_LOCATION = "classpath:mybatis.xml";
//
//    /* Ant 风格路径表达式
//     * **	匹配0或者更多的目录
//     * 如: \/**\/example	匹配 /app/example, /app/foo/example, 和 /example
//     */
//    static final String MAPPER_LOCATION = "classpath:sql/**/*.xml";
//    static final String ENTITY = "com.rt.mes.processmanagement.dao.entity";
//
//    @Bean(name = "sqlSessionFactory")
//    public SqlSessionFactory sqlSessionFactory() throws Exception {
//        SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
//
//        sqlSessionFactoryBean.setDataSource(dataSource);
//
//        //添加XML目录
//        ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
//        try {
//            sqlSessionFactoryBean.setMapperLocations(resolver.getResources(MAPPER_LOCATION));
//        } catch (Exception e) {
//            e.printStackTrace();
//            throw new RuntimeException(e);
//        }
//
//        /* sql 中的parameterType可以不用带全路径。
//        如: parameterType="com.rt.mes.processmanagement.dao.entity.CalAutoRegNumEntity"
//        可以写成： parameterType="CalAutoRegNumEntity"
//        缺点是如果装了free mybatis插件， CalAutoRegNum会变成红色
//        */
//        sqlSessionFactoryBean.setTypeAliasesPackage(ENTITY);
//        Resource r = new PathMatchingResourcePatternResolver().getResource(CONFIG_LOCATION);
//        sqlSessionFactoryBean.setConfigLocation(r);
//
//
//        SqlSessionFactory sqlSession = sqlSessionFactoryBean.getObject();
//        /*创建SqlSessionFactory的同时，
//        将其配置项MapUnderscoreToCamelCase设置为true，
//        如数据库列 user_name将自动映射到pojo中的userName属性*/
//        sqlSession.getConfiguration().setMapUnderscoreToCamelCase(true);
//        return sqlSession;
//    }
//}
